<template>
  <div class="about">
    <my-header>
      <span class="left"></span>
      <span class="title">图书商城</span>
      <span class="right" @click="$router.push('/myBookBox')">我的书架</span>
    </my-header>
    <div class="search-box">
      <my-input placeholder="输入书名搜索" v-model="$store.state.content"></my-input>
    </div>
    <div>
      <ul class="book-box">
        <my-card v-for="item in $store.getters.books" :key="item.id">
          <img :src="item.img" alt="book-img">
          <div>
            <p>{{item.desc}}</p>
            <section :style="{
              color: $store.state.backColor
            }">
                <span>{{item.name}}</span>
                <span @click="checkBook(item)" class="iconfont iconcuowu-"></span>
            </section>
          </div>
        </my-card>
      </ul>
    </div>
  </div>
</template>
<script>
import myHeader from '@/components/myHeader/myHeader'
import myInput from '@/components/myInput/myInput' 
import myCard from '@/components/myCard/myCard'
import axios from 'axios'
import { mapMutations } from 'vuex'
export default {
  components: {
    myHeader,
    myInput,
    myCard
  },
  data() {
    return {
    }
  },
  created() {
    axios.get('data.json').then(res => {
      this.$store.commit('changeBooks', res.data)
    })
  },

  methods: {
    ...mapMutations(['checkBook'])
  }
}
</script>
<style lang="scss" scoped>
  .about {
    width: 100%;
    height: 100%;
    overflow: auto;
  }
  .search-box {
    input {
      border: none;
      background-color: #ccc;
      border-radius: 0;
      font-size: 18px;
      outline: none;
    }
  }
  .book-box {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    li {
      flex-basis: 50%;
      font-size: 12px;
      height: 300px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 15px;
      box-shadow: 3px 3px 15px #999;
      p {
        text-indent: 2em;
        width: 100%;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        color:#ccc;
        line-height: 18px;
      }
      section {
        display: flex;
        width: 100%;
        justify-content: space-between;
        font-size: 14px;
      }
      .iconfont {
        transform: rotate(45deg)
      }
      img {
        width: 100%;
        height: auto;
      }
    }
  }
</style>
